# coding=utf-8

from typing import List
import openpyxl
from datetime import datetime
from openpyxl.styles import Alignment


class PropertyConfig:

    def __init__(self, name, serviceId, ap_prot, vp_port, files) -> None:
        self.name = name

def wirteSheetHeader(sheet):
    sheet.cell(1, 1, "Date")
    sheet.cell(1, 2, "PropIdName")
    sheet.cell(1, 3, "PropIdValue")
    sheet.cell(1, 4, "Change_Mode")
    sheet.cell(1, 5, "Access_Mode")
    sheet.cell(1, 6, "VehicleArea")
    sheet.cell(1, 7, "Value_Type")
    sheet.cell(1, 8, "Signal_Value_Enum")
    sheet.cell(1, 9, "Description")
    sheet.cell(1, 10, "Author")


def gen_prop_interface_excle(propModules):
    excle = openpyxl.load_workbook(
        "./config/vehicleProp/Property_ID.xlsx")

    sheetColumns=['A','B','C',"D",'E','F','G','H','I','J']

    sheetNames = excle.sheetnames
    for sheet in sheetNames:
        excle.remove(excle[sheet])

    sheet = excle.create_sheet("PropertyID")
    wirteSheetHeader(sheet)
    for sheet_column in sheetColumns:
        dimensions = sheet.column_dimensions[sheet_column]
        if sheet_column == 'B' or sheet_column == 'H':
            dimensions.width = 25
        elif sheet_column == 'I':
            dimensions.width = 30
        else:
            dimensions.width = 15

    index = 2
    # 创建新的内容
    for prop in sorted(propModules, key=lambda prop:datetime.strptime(prop.prop_date,"%Y-%m-%d").toordinal()):
        sheet.cell(index, 1, prop.prop_date)
        sheet.cell(index, 2, prop.prop_name)
        sheet.cell(index, 3, prop.prop_id)
        sheet.cell(index, 4, prop.change_mode)
        sheet.cell(index, 5, prop.access_mode)
        sheet.cell(index, 6, prop.prop_area)
        sheet.cell(index, 7, prop.prop_type)
        if prop.propEnums != None:
            sheet.cell(index, 8, prop.propEnums)
        sheet.cell(index, 9, prop.description)
        sheet.cell(index, 10, prop.prop_author)
        index += 1
    excle.save("./config/vehicleProp/Property_ID.xlsx")
